//
//  FirstViewController.m
//  eNew
//
//  Created by lanou3g on 15-4-29.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "FirstViewController.h"
#import "FirstCollectionViewCell.h"
#import "RESideMenu.h"
#import "FirstView.h"
#import "DetailTableViewController.h"


@interface FirstViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, retain) NSArray *firstLableArray;         //目录
@property (nonatomic, retain) FirstView *firstView;
@property (nonatomic, retain) NSArray *urlArray;        //网址数组

@end

@implementation FirstViewController

- (void)loadView {
    self.firstView = [[[FirstView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
    self.view = _firstView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"e资讯";
    self.firstLableArray = @[@"zhuanfengle.png", @"gaoxiao.png",@"meinv.png",@"shipin.png",@"lieqi.png",@"shehui.png",@"jiankang.png",@"kuwan.png"];
    self.urlArray = @[@"http://api.95xiaobao.com/news/hotforwardnews/1-20-0.html?        clientId=930749509&version=1.4",
                      @"http://api.95xiaobao.com/news/newsinfo/9-1-20-0.html?clientid=930749509&version=1.4",
                      @"http://api.95xiaobao.com/news/newsinfo/20-1-20-0.html?clientid=930749509&version=1.4",
                      @"http://api.95xiaobao.com/news/newsinfo/15-1-20-0.html?clientid=930749509&version=1.4",
                      @"http://api.95xiaobao.com/news/newsinfo/3-1-20-0.html?clientid=930749509&version=1.4",
                      @"http://api.95xiaobao.com/news/newsinfo/2-1-20-0.html?clientid=930749509&version=1.4",
                      @"http://api.95xiaobao.com/news/newsinfo/15-1-20-0.html?clientid=930749509&version=1.4",
                      @"http://api.95xiaobao.com/news/newsinfo/6-1-20-0.html?clientid=930749509&version=1.4"];
    
    self.navigationItem.leftBarButtonItem = ({
        [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-shezhi"] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarButtonItemAction:)] autorelease];
    });
    
    self.firstView.collectionView.delegate = self;
    self.firstView.collectionView.dataSource = self;
    
    //注册cell
    [_firstView.collectionView registerClass:[FirstCollectionViewCell class] forCellWithReuseIdentifier:@"movie"];
    
}
#pragma mark 左上角点击事件
- (void)leftBarButtonItemAction:(UIBarButtonItem *)sender {
    
    //抽屉第一项--给蝉游攻略提意见--
    RESideMenuItem *one = [[RESideMenuItem alloc] initWithTitle:@"收藏" action:^(RESideMenu *menu, RESideMenuItem *item) {
        [menu hide];
          }];
    RESideMenuItem *two = [[RESideMenuItem alloc] initWithTitle:@"收藏" action:^(RESideMenu *menu, RESideMenuItem *item) {
        [menu hide];
    }];
    RESideMenuItem *three = [[RESideMenuItem alloc] initWithTitle:@"收藏" action:^(RESideMenu *menu, RESideMenuItem *item) {
        [menu hide];
    }];
    RESideMenuItem *four = [[RESideMenuItem alloc] initWithTitle:@"收藏" action:^(RESideMenu *menu, RESideMenuItem *item) {
        [menu hide];
    }];
    RESideMenu *sideMenu = [[RESideMenu alloc] initWithItems:@[one,two,three,four]];
    
    [sideMenu show];
}

#pragma mark 实现collection代理
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FirstCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"movie" forIndexPath:indexPath];
    //cell.label.text = _firstLableArray[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:_firstLableArray[indexPath.row]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DetailTableViewController *DetailVC = [[DetailTableViewController new] autorelease];
    DetailVC.value = _urlArray[indexPath.row];
    [self.navigationController pushViewController:DetailVC animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc
{
    [_firstView release];
    [_urlArray release];
    [super dealloc];
}
@end
